{$CLEO .cs}
thread 'AI_SHAMAL'
9@ = 0 //transmitter
7@ = -1 //plane
8@ = -1 //actor
10@ = -1 //plane marker
11@ = -1 //pathID
12@ = -1 //pathDetector
27@ = -1 //long angle
26@ = -1 //long coord
25@ = -1 //long coord
24@ = -1 //long coord

0@ = -1 //coord
1@ = -1 //coord
2@ = -1 //coord
3@ = -1 //temp value
4@ = -1 //angle
5@ = -1 //health
6@ = -1 //speed

:start
wait 0
if
Player.Defined($PLAYER_CHAR)
jf @start
if
80FE:   not actor $PLAYER_ACTOR sphere 0 in_sphere -1594.2548 -106.9400 14.0829 radius 250.0 250.0 250.0
jf @start

:ava
wait 10
if
Model.Available(#SHAMAL)
jf @load
wait 10
if
Model.Available(#WMYPLT)
jf @load1
jump @available

:load
Model.Load(#SHAMAL)
wait 10
jump @ava

:load1
Model.Load(#WMYPLT)
wait 10
jump @ava

:available
Car.Create(7@, #SHAMAL, -1594.2548, -106.9400, 14.0829)
Car.Angle(7@) = 315.0
08E6: set_plane 7@ landing_gear 0 
020A: set_car 7@ door_status_to 4
0129: 8@ = create_actor_pedtype 4 model #WMYPLT in_car 7@ driverseat
Model.Destroy(#WMYPLT)
Model.Destroy(#SHAMAL)
11@ = 44
12@ = 0
27@ = 315.0
26@ = -1594.2548
25@ = -106.9400
24@ = 14.0829
if
9@ == 1
jf @loadpath
0ACE: show_formatted_text_box "SHAMAL respawned at San Fierro."
Marker.CreateAboveaCTOR(10@, 8@)
Marker.SetColor(10@, 3)

:loadpath
wait 10
if 
07C1:   path 11@ available
jf @loadpath1
jump @movingon

:loadpath1
07C0: load_path 11@
wait 10
jump @loadpath

:movingon
05EB: assign_car 7@ to_path 11@
0873: release_path 11@
if
9@ == 1
jf @checks
0ACE: show_formatted_text_box "SHAMAL is now taking off."

:checks
gosub @dead
gosub @transmit
gosub @landinggear
if
860E:   not car 7@ assigned_to_path
jf @checks

:release
06C5: release_car 7@ from_path
12@ += 1
if
0029:   12@ >= 3
jf @detectpath
jump @repeat

:detectpath
3@ = 0
if
12@ == 1
jf @detectpath1
26@ = 1480.4110
25@ = 1697.7520
24@ = 10.7323
27@ = 0.0
if
9@ == 1
jf @putat
0ACE: show_formatted_text_box "SHAMAL is now in Las Venturas."

:putat
gosub @dead
gosub @transmit
3@ += 1 
25@ += 0.5
Car.Angle(7@) = 27@
Car.PutAt(7@, 26@, 25@, 24@)
if 
3@ == 37
jf @putat 
gosub @angle
26@ = 1479.7693
25@ = 1716.3430
24@ = 10.7705
27@ = 180.0
11@ = 48
jump @loadpath

:detectpath1
if
12@ == 2
jf @repeat
26@ = 2046.3146
25@ = -2492.6272
24@ = 13.4629
27@ = 270.0
gosub @angle
27@ = 90.0
if
9@ == 1
jf @putat1
0ACE: show_formatted_text_box "SHAMAL is now in Los Santos."

:putat1
gosub @dead
gosub @transmit 
3@ += 1 
26@ += -0.5
Car.Angle(7@) = 27@
Car.PutAt(7@, 26@, 25@, 24@)
if 
  3@ == 931
else_jump @putat1
26@ = 1580.6041
25@ = -2493.8977
24@ = 13.4694
gosub @angle
27@ = 270.0
11@ = 42
jump @loadpath

:repeat
26@ = -1544.5707
25@ = -43.9380
24@ = 14.0603
27@ = 135.0
if
3@ == 1
jf @repeat1
0ACE: show_formatted_text_box "SHAMAL is now in San Ferrio."

:repeat1
gosub @dead 
gosub @transmit
3@ += 1
26@ -= 0.5
25@ -= 0.5
Car.Angle(7@) = 27@
Car.PutAt(7@, 26@,25@,24@)
if
3@ == 100
jf @repeat1
11@ = 44
12@ = 0
26@ = -1594.2548
25@ = -106.9400
24@ = 14.0829
gosub @angle
27@ = 315.0
jump @loadpath

:landinggear
Car.StorePos(7@, 0@, 1@, 2@)
if
2@ >= 50.0
jf @landinggear1
08E6: set_plane 7@ landing_gear 1
return

:landinggear1
08E6: set_plane 7@ landing_gear 0
return

:angle
3@ = 0

:angle2
gosub @dead
gosub @transmit 
000B: 27@ += 1.0
000A: 3@ += 1
Car.Angle(7@) = 27@
Car.PutAt(7@, 26@, 25@, 24@)
if 
   3@ >= 180 
else_jump @angle2
3@ = 0
return

:dead
wait 0
if and
not 7@ == -1
not 8@ == -1
jf @ende
if and
not Car.Wrecked(7@)
0185:  car 7@ health >= 250
not Actor.Dead(8@)
Actor.InCar(8@, 7@)
jf @end
return

:end
0ABF: set_vehicle 7@ engine_state_to 0
Actor.RemoveReferences(8@)
Car.RemoveReferences(7@)
06C5: release_car 7@ from_path
if
9@ == 1
jf @start
0ACE: show_formatted_text_box "Something very bad happened to the SHAMAL." 
Marker.Disable(10@)
jump @start

:ende
Marker.Disable(10@)
Actor.RemoveReferences(8@)
Car.RemoveReferences(7@)
jump @start

:transmit
if
0ADC: test_cheat "SHAMAL"
jf @info
if
9@ == 0
jf @off
9@ = 1
Marker.CreateAboveActor(10@, 8@)
Marker.SetColor(10@, 3)
0ACE: show_formatted_text_box "SHAMAL transmitter online. Type SHAMAL again to turn off or hold H and 4 to view info."
return

:off
9@ = 0
Marker.Disable(10@)
0ACE: show_formatted_text_box "SHAMAL transmitter offline. Type SHAMAL to turn on."
return

:info
if
0AB0:  key_pressed 72
0aa1:
if
0AB0:  key_pressed 52
0aa1:
if
9@ == 1
0AA1: return_if_false
0227: 5@ = car 7@ health
02E3: 6@ = car 7@ speed
Car.StorePos(7@, 0@, 1@, 2@)
4@ = Car.Angle(7@)
0ACE: show_formatted_text_box "SHAMAL Health %d Speed %f at %f %f %f Angle %f" 5@ 6@ 0@ 1@ 2@ 4@
return